import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';

enum Api {
  list = "/system-service/accessKey/listAccessKey",
  getBaseInfo = "/system-service/accessKey/getAccessKeyBaseInfoById",
  getAccessKeyDetails = "/system-service/accessKey/getAccessKeyDetails",
  save = "/system-service/accessKey/saveAccessKey",
  edit = "/system-service/accessKey/updateAccessKeyById",
  delete = "/system-service/accessKey/deleteAccessKeyById",
  deleteBatch = "/system-service/accessKey/deleteAccessKeyByIds",
  refreshCache = "/system-service/config/refreshCache",
}


/**
 * 查询
 * @param params
 */
export const listAccessKey = (params) => {
  return defHttp.get({url: Api.list, params});
}

/**
 * 查询, 通过id查找
 * @param params
 */
export const getAccessKeyBaseInfo = (params) => {
  return defHttp.get({url: Api.getBaseInfo, params});
}

export const getAccessKeyDetailsById = (params) => {
  return defHttp.get({url: Api.getAccessKeyDetails, params});
}

export const listApp = (params) => {
  // return defHttp.get({url: Api.list, params});
}

/**
 * 查询租户列表
 * @param params
 */
export const refreshCache = () => {
  return defHttp.delete({url: Api.refreshCache});
}

/**
 * 保存或者更新通告
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}

/**
 * 删除通告
 * @param params
 */
export const deleteAccessKey= (params, handleSuccess) => {
  return defHttp.delete({url: Api.delete, data: params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除租户
 * @param params
 */
export const batchDeleteAccessKey = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
